﻿'Params
'limit (Optional) : The number of results to fetch per page. Defaults to 30.
'page (Optional) : The page number to fetch. Defaults to first page.
'album (Required) : The album name
'api_key (Required) : A Last.fm API key.

'Auth
' This service does not require authentication. 

Public Structure AlbumSearchResponse
	Public albums() As Album

End Structure

Public Class AlbumSearch
	Inherits BaseRequest
	Dim album As String = ""
	Dim limit As String = ""
	Dim page As String = ""

	Public xmlresponse As XDocument = Nothing

	Public Sub New(album As String, limit As String, page As String)
		Me.album = album
		Me.limit = limit
		Me.page = page
	End Sub

	Public Sub sendRequest()
		ClearMembers()

		AddMember("method", "album.search")

		AddMember("album", album, True)
		AddMember("limit", limit, False)
		AddMember("page", page, False)
		AddMember("api_key", My.Settings.api_key, False)

		xmlresponse = sendPOSTResponse()
	End Sub

	Public Function getResponse() As AlbumSearchResponse
		Dim response As AlbumSearchResponse = Nothing
		Dim count As Integer
		Try
			count = xmlresponse.<lfm>.<results>.<albummatches>.<album>.Count()
		Catch ex As Exception
			Return response
		End Try
		If (count > 0) Then
			ReDim response.albums(count - 1)
			For i As Integer = 0 To count - 1
				response.albums(i) = New Album(xmlresponse.<lfm>.<results>.<albummatches>.<album>(i))
			Next
		End If
		Return response
	End Function

End Class
